


cap confirm file "$data_out/Discharges.dta" 
if _rc!=0 { 
do "$Outcomes/Discharges.do"
}
else use "$data_out/Discharges.dta", clear 

label var ed_prescription "Prescription in ED"
label var discharge_365 "Any Discharge within 1 Year"
label var discharge_730 "Any Discharge within 2 Years"
label var honorable_365 "Honorable Discharge within 1 Year"
label var honorable_730 "Honorable Discharge within 2 Years"
label var not_honorable_365 "Other Discharge within 1 Year"
label var not_honorable_730 "Other Discharge within 2 Years"



label var disability_365 "Disability-Related Discharge within 1 Year"
label var negative_365 "Discipline-Related Discharge within 1 Year"
label var ABCP_365 "Failure to Meet Weight or Body Fat Standards Discharge within 1 Year"
label var contractual_365 "Non-Renewal of Contract or Retirement within 1 Year"
label var non_discipline_365 "Other Non-Discipline Related Discharge within 1 Year"
label var ASAP_365 "Substance Abuse Discharge within 1 Year"
label var uncharacterized_365 "Uncharacterized Discharge within 1 Year"


foreach outcome in death_365 discharge_365 negative_365  contractual_365 non_discipline_365 disability_365 ASAP_365 ABCP_365 uncharacterized_365 honorable_365 not_honorable_365 {
eststo `outcome'_C1:	ivreghdfe `outcome' $spec1


eststo `outcome'_Q1:	ivreghdfe `outcome' $spec2
estadd ysumm, replace
}

foreach outcome in death_730 discharge_730 negative_730  contractual_730 non_discipline_730 disability_730 ASAP_730 ABCP_730 uncharacterized_730 honorable_730 not_honorable_730 {
eststo `outcome'_C2:	ivreghdfe `outcome' $spec1
estadd ysumm, replace


eststo `outcome'_Q2:	ivreghdfe `outcome' $spec2
}

#delimit ;

	//word
esttab *_C1 using "discharge_365.rtf" , 
	replace label se star(* 0.10 ** 0.05 *** 0.01)
	b(4) se(4)
	stats(ymean N ,
	fmt(a2 %-9.0fc)
	label("Sample Mean" "Observations"))
		keep(ed_prescription)
		title(IV Results for Military Discharges - Prescribing Rate Instrument);
		
		esttab *_Q1 using "discharge_365.rtf" , 
	append label se star(* 0.10 ** 0.05 *** 0.01)
	b(4) se(4)
	stats(ymean N ,
	fmt(a2 %-9.0fc)
	label("Sample Mean" "Observations"))
		keep(ed_prescription)
		title(IV Results for Military Discharges - 4th vs 1st Quartile Instrument);
		
esttab *_C2 using "discharge_730.rtf" , 
	replace label se star(* 0.10 ** 0.05 *** 0.01)
	b(4) se(4)
	stats(ymean N ,
	fmt(a2 %-9.0fc)
	label("Sample Mean" "Observations"))
		keep(ed_prescription)
		title(IV Results for Military Discharges - Prescribing Rate Instrument);
		
		esttab *_Q2 using "discharge_730.rtf" , 
	append label se star(* 0.10 ** 0.05 *** 0.01)
	b(4) se(4)
	stats(ymean N ,
	fmt(a2 %-9.0fc)
	label("Sample Mean" "Observations"))
		keep(ed_prescription)
		title(IV Results for Military Discharges - 4th vs 1st Quartile Instrument);

 
#delimit cr
